home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Gadgets / simplegad.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  5KB  |  153 lines

  1. ;/* simplegad.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 simplegad.c
  3. Blink FROM LIB:c.o,simplegad.o TO simplegad LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33.  
  34. /*
  35. ** simplegad.c - show the use of a button gadget.
  36. */
  37.  
  38. #define INTUI_V36_NAMES_ONLY
  39.  
  40. #include <exec/types.h>
  41. #include <intuition/intuition.h>
  42. #include <intuition/intuitionbase.h>
  43.  
  44. #include <clib/exec_protos.h>
  45. #include <clib/intuition_protos.h>
  46.  
  47. #include <stdio.h>
  48.  
  49. #ifdef LATTICE
  50. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  51. int chkabort(void) { return(0); }  /* really */
  52. #endif
  53.  
  54. struct Library *IntuitionBase;
  55.  
  56. #define BUTTON_GAD_NUM   (3)
  57. #define MYBUTTONGADWIDTH (100)
  58. #define MYBUTTONGADHEIGHT (50)
  59.  
  60. /* NOTE that the use of constant size and positioning values are
  61. ** not recommended; it just makes it easy to show what is going on.
  62. ** The position of the gadget should be dynamically adjusted depending
  63. ** on the height of the font in the title bar of the window.
  64. */
  65.  
  66. UWORD buttonBorderData[] =
  67.     {
  68.     0,0, MYBUTTONGADWIDTH + 1,0, MYBUTTONGADWIDTH + 1,MYBUTTONGADHEIGHT + 1,
  69.     0,MYBUTTONGADHEIGHT + 1, 0,0,
  70.     };
  71.  
  72. struct Border buttonBorder =
  73.     {
  74.     -1,-1,1,0,JAM1,5,buttonBorderData,NULL,
  75.     };
  76.  
  77. struct Gadget buttonGad =
  78.     {
  79.     NULL, 20,20, MYBUTTONGADWIDTH,MYBUTTONGADHEIGHT,
  80.     GFLG_GADGHCOMP, GACT_RELVERIFY | GACT_IMMEDIATE,
  81.     GTYP_BOOLGADGET, &buttonBorder, NULL, NULL,0,NULL,BUTTON_GAD_NUM,NULL,
  82.     };
  83.  
  84. /*
  85. ** routine to show the use of a button (boolean) gadget.
  86. */
  87. VOID main(int argc, char **argv)
  88. {
  89. struct Window *win;
  90. struct IntuiMessage *msg;
  91. struct Gadget *gad;
  92. ULONG  class;
  93. BOOL done;
  94.  
  95. /* make sure to get intuition version 37, for OpenWindowTags() */
  96. IntuitionBase = OpenLibrary("intuition.library", 37);
  97. if (IntuitionBase)
  98.     {
  99.     if (win = OpenWindowTags(NULL,
  100.                             WA_Width, 400,
  101.                             WA_Height, 100,
  102.                             WA_Gadgets, &buttonGad,
  103.                             WA_Activate, TRUE,
  104.                             WA_CloseGadget, TRUE,
  105.                             WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_GADGETUP |
  106.                                       IDCMP_CLOSEWINDOW,
  107.                             TAG_END))
  108.         {
  109.         done = FALSE;
  110.         while (done == FALSE)
  111.             {
  112.             Wait(1L << win->UserPort->mp_SigBit);
  113.             while ( (done == FALSE) &&
  114.                     (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  115.                 {
  116.                 /* Stash message contents and reply, important when message
  117.                 ** triggers some lengthy processing
  118.                 */
  119.                 class = msg->Class;
  120.  
  121.                 /* gadget address is ONLY valid for gadget messages! */
  122.                 if ((class == IDCMP_GADGETUP) || (class == IDCMP_GADGETDOWN))
  123.                     gad = (struct Gadget *)(msg->IAddress);
  124.  
  125.                 ReplyMsg((struct Message *)msg);
  126.  
  127.                 /* switch on the type of the event */
  128.                 switch (class)
  129.                     {
  130.                     case IDCMP_GADGETUP:
  131.                         /* caused by GACT_RELVERIFY */
  132.                         printf("received an IDCMP_GADGETUP, gadget number %d\n",
  133.                                gad->GadgetID);
  134.                         break;
  135.                     case IDCMP_GADGETDOWN:
  136.                         /* caused by GACT_IMMEDIATE */
  137.                         printf("received an IDCMP_GADGETDOWN, gadget number %d\n",
  138.                                gad->GadgetID);
  139.                         break;
  140.                     case IDCMP_CLOSEWINDOW:
  141.                         /* set a flag that we are done processing events... */
  142.                         printf("received an IDCMP_CLOSEWINDOW\n");
  143.                         done = TRUE;
  144.                         break;
  145.                     }
  146.                 }
  147.             }
  148.         CloseWindow(win);
  149.         }
  150.     CloseLibrary(IntuitionBase);
  151.     }
  152. }
  153.